//
//  Person.m
//  归档和恢复
//
//  Created by 安怀远 on 15/6/17.
//  Copyright (c) 2015年 安怀远. All rights reserved.
//

#import "People.h"

@implementation People
//工厂方法
+(id)initPeopleWithInfo:(NSString *)name age:(NSString *)age phoneNum:(NSString *)phoneNum headImage:(UIImage *)headImage{

    People *people=[[People alloc] init];
    people.age=age;
    people.name=name;
    people.phoneNum=phoneNum;
    people.headImage=headImage;


    return people;
}
//实现NsCoding的协议方法
//归档 序列化
-(void)encodeWithCoder:(NSCoder *)aCoder{
    [aCoder encodeObject:_name forKey:@"name"];
    [aCoder encodeObject:_age forKey:@"age"];
    [aCoder encodeObject:_phoneNum forKey:@"phone"];
    NSData *imageData=UIImagePNGRepresentation(_headImage);
    [aCoder encodeObject:imageData forKey:@"image"];
}
//恢复  反序列化
-(id)initWithCoder:(NSCoder *)aDecoder{

    self=[super init];
    if (self) {
        
        _name=[aDecoder decodeObjectForKey:@"name"];
        _age=[aDecoder decodeObjectForKey:@"age"];
        _phoneNum=[aDecoder decodeObjectForKey:@"phone"];
        NSData *imageData=[aDecoder decodeObjectForKey:@"image"];
        _headImage=[UIImage imageWithData:imageData];
        
        
        
    }
    return self;
}



@end
